package com.nandi.deviceinstall.ui.activity


import android.annotation.SuppressLint
import android.content.Intent
import android.view.LayoutInflater
import com.nandi.deviceinstall.R

import com.nandi.deviceinstall.base.BaseMvpActivity
import com.nandi.deviceinstall.contract.LoginContract
import com.nandi.deviceinstall.presenter.MainPresenter
import com.nandi.deviceinstall.util.ProgressDialog

import com.nandi.deviceinstall.bean.LoginBean
import com.nandi.deviceinstall.util.CustomToast

import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.dialog_tips.view.*


class MainActivity : BaseMvpActivity<MainPresenter>(), LoginContract.View {
    override fun onSuccess(bean: LoginBean) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onError(msg: String, code: Int) {
        CustomToast.showToast(context,msg)
    }


    override val layoutId: Int
        get() = R.layout.activity_main


    override fun initView() {
        mPresenter = MainPresenter()
        mPresenter!!.attachView(this)
        initListener()
    }

    private fun initListener() {
        equipmentStepPoint.setOnClickListener {
            val intent = Intent(context, EquipmentStepActivity::class.java)
            intent.putExtra("action","add")
            startActivity(intent)
        }
        equipmentInfrastructure.setOnClickListener {
            initTipsDialog()
        }
        equipmentBinding.setOnClickListener {
            val intent = Intent(context, EquipmentBindingActivity::class.java)
            intent.putExtra("action","add")
            startActivity(intent)
        }
    }

    /*override fun onSuccess(bean: BaseObjectBean<LoginBean>) {

        //Toast.makeText(this, bean.errorMsg, Toast.LENGTH_SHORT).show()

    }*/

    override fun showLoading() {
        ProgressDialog.getInstance()!!.show(this)
    }

    override fun hideLoading() {
        ProgressDialog.getInstance()!!.dismiss()
    }

    @SuppressLint("SetTextI18n", "InflateParams")
    private fun initTipsDialog() {
        val inflate = LayoutInflater.from(context).inflate(R.layout.dialog_tips, null)
        inflate.tips.text = "温馨提示"
        inflate.content.text = "抱歉，您暂未开通此权限"
        val show = android.app.AlertDialog.Builder(context)
                .setView(inflate)
                .setCancelable(false)
                .show()
        inflate.cancels.setOnClickListener {
            show.dismiss()
        }
    }

}
